package com.snap.vseries.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.snap.vseries.R;
import com.snap.vseries.base.BaseRecycleAdapter;
import com.snap.vseries.base.BaseViewHolder;
import com.snap.vseries.bean.ExpEntity;
import com.snap.vseries.ui.ExpResultActivity;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
 * 近期实验
 */
public class HomeExperimentAdapter extends BaseRecycleAdapter<ExpEntity> {
    public HomeExperimentAdapter(Context context, List<ExpEntity> dataList) {
        super(context, dataList);
    }

    @Override
    public void bindData(BaseViewHolder holder, ExpEntity data, int position) {
        SimpleDateFormat format = new SimpleDateFormat("d MMM yyyy", Locale.US);
        String time = format.format(new Date(data.getStartTime()));
        holder.setText(R.id.tv_name, data.getName())
                .setText(R.id.tv_date, time);
        holder.setOnItemClickLitener(new BaseViewHolder.onItemCommonClickListener() {
            @Override
            public void onItemClickListener(View view, int position) {
                Intent expResult = new Intent(mContext, ExpResultActivity.class);
                expResult.putExtra("fileName", data.getName());
                mContext.startActivity(expResult);
            }
        });
        if (data.isRead()) {
            holder.setViewVisibility(R.id.new_tv, View.GONE);
        } else {
            holder.setViewVisibility(R.id.new_tv, View.VISIBLE);
        }
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_home_experiment;
    }
}
